package com.hns.phone.energy.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.common.domain.GridPage;
import com.hns.can.common.service.CommonInitParamService;
import com.hns.can.common.web.BaseController;
import com.hns.frame.mybatis.Pagination;
import com.hns.phone.common.vo.PhoneParamsVo;
import com.hns.phone.energy.service.PhoneLineEnergyService;
import com.hns.phone.energy.vo.CarEnergyTendencyVo;
import com.hns.phone.energy.vo.EnergyAdviceBhvVo;
import com.hns.phone.energy.vo.EnergyExceptionRanking;
import com.hns.phone.energy.vo.EnergyRiseDriverVo;
import com.hns.phone.energy.vo.EnergyStatusConcludeVo;
import com.hns.phone.energy.vo.EnergyStatusInfoVo;
import com.hns.phone.energy.vo.LineEnergyOperationVo;

@Controller
@RequestMapping("/api/phoneLineEnergy")
public class PhoneLineEnergyController extends BaseController {
	
	@Autowired
	private PhoneLineEnergyService phoneLineEnergyService;
	
	@Autowired
    protected CommonInitParamService commonInitParamService;
	
	@SuppressWarnings("serial")
	private Map<String, String> typeMap = new HashMap<String, String>(){
		{
			put("oil", "030901");
			put("elec", "030902");
			put("gas", "030903");
		}
	};
	
	@SuppressWarnings("serial")
	private Map<String, String> costMap = new HashMap<String, String>(){
		{
			put("oil", "031201");
			put("elec", "031202");
			put("gas", "031203");
		}
	};
	
	@SuppressWarnings("serial")
	private Map<String, String> statusMap = new HashMap<String, String>(){
		{
			put("oil", "031201");
			put("elec", "031202");
			put("gas", "031203");
		}
	};
	
	
	@RequestMapping("/getOperationInfo")
	@ResponseBody
	public Object getOperationInfo(PhoneParamsVo vo){
		vo.setUserid(this.getPhoneCurrentUser().getId());
		List<LineEnergyOperationVo> list = phoneLineEnergyService.getOperationInfo(vo);
		return this.getReturnResult(list);
	}
	
	@RequestMapping("/getMileTendency")
	@ResponseBody
	public Object getMileTendency(PhoneParamsVo vo){
		vo.setUserid(this.getPhoneCurrentUser().getId());
		List<CarEnergyTendencyVo> list = phoneLineEnergyService.getMileTendency(vo);
		return this.getReturnResult(list);
	}
	
//	@RequestMapping("/getLineMileList")
//	@ResponseBody
//	public Object getLineMileList(PhoneParamsVo vo){
//		commonInitParamService.dateType2DateTime(vo, vo.getDateType());
//		vo.setUserid(this.getPhoneCurrentUser().getId());
//		Pagination page = phoneLineEnergyService.getLineMileList(vo);
//		GridPage grid = new GridPage(page);
//		return this.getReturnResult(grid);
//	}
	
	@RequestMapping("/getEnergyCostTendency")
	@ResponseBody
	public Object getEnergyCostTendency(PhoneParamsVo vo){
		vo.setEnerType(typeMap.get(vo.getEnerType()));
		vo.setUserid(this.getPhoneCurrentUser().getId());
		List<CarEnergyTendencyVo> list = phoneLineEnergyService.getEnergyCostTendency(vo);
		return this.getReturnResult(list);
	}
	
	@RequestMapping("/getEnergyCostList")
	@ResponseBody
	public Object getEnergyCostList(PhoneParamsVo vo){
		vo.setEnerType(costMap.get(vo.getEnerType()));
		vo.setUserid(this.getPhoneCurrentUser().getId());
		Pagination page = phoneLineEnergyService.getEnergyCostList(vo);
		GridPage grid = new GridPage(page);
		return this.getReturnResult(grid);
	}
	
	@RequestMapping("/getEnergyStatusInfo")
	@ResponseBody
	public Object getEnergyStatusInfo(PhoneParamsVo vo){
		vo.setUserid(this.getPhoneCurrentUser().getId());
		List<EnergyStatusInfoVo> list = phoneLineEnergyService.getEnergyStatusInfo(vo);
		return this.getReturnResult(list);
	}
	
	@RequestMapping("/getEnergyStatusConclude")
	@ResponseBody
	public Object getEnergyStatusConclude(PhoneParamsVo vo){
		vo.setUserid(this.getPhoneCurrentUser().getId());
		List<EnergyStatusConcludeVo> list = phoneLineEnergyService.getEnergyStatusConclude(vo);
		return this.getReturnResult(list);
	}
	
	@RequestMapping("/getEnergyRiseDrivingBhv")
	@ResponseBody
	public Object getEnergyRiseDrivingBhv(PhoneParamsVo vo){
		vo.setUserid(this.getPhoneCurrentUser().getId());
		List<EnergyRiseDriverVo> list = phoneLineEnergyService.getEnergyRiseDrivingBhv(vo);
		return this.getReturnResult(list);
	}
	
	@RequestMapping("/getEnerAdviceBhv")
	@ResponseBody
	public Object getEnerAdviceBhv(PhoneParamsVo vo){
		vo.setUserid(this.getPhoneCurrentUser().getId());
		List<EnergyAdviceBhvVo> list = phoneLineEnergyService.getEnerAdviceBhv(vo);
		return this.getReturnResult(list);
	}
	
	/**
	 * 形式里程列表（前五）
	 * @param vo
	 * @return
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	@RequestMapping("/getLineMileListForFive")
	@ResponseBody
	public Object getLineMileListForFive(PhoneParamsVo vo){
		vo.setUserid(this.getPhoneCurrentUser().getId());
		List<EnergyExceptionRanking> list = phoneLineEnergyService.getLineMileListForFive(vo);
		return this.getReturnResult(list);
	}
}
